<?php

header('Content-type: text/html; charset=utf-8');

ini_set("display_errors", 1);

require_once dirname(__FILE__).'/cf/config.php';
require_once cf\Config::path.'param.php';
require_once cf\Config::path.'image.php';
require_once cf\Config::path.'api/page.php';
require_once cf\Config::path.'user.php';

define('SMARTY_DIR','./smarty/');
require_once SMARTY_DIR . 'Smarty.class.php';

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$smarty->addPluginsDir(cf\Config::path.'components');


date_default_timezone_set('UTC');
setlocale(LC_ALL,"en_US.utf8");

$smarty->assign('topMenu',cf\api\page\getTree('main_menu',true));
$smarty->assign('bottomMenu',cf\api\page\getTree('bottom_menu',true));

$pageId = null;
$smarty->assignByRef('pageId',$pageId);

$admin = new cf\User(cf\User::findByLogin('admin'));
$smarty->assign('email',$admin->email());
$smarty->assign('phones',cf\api\page\getText('phone_numbers'));

function getCrumbs($branch) {
	$crumbs = array();

	foreach ($branch as $nm => $p) {
		$link = '';
		if ($p['link']) {
			$link = $p['link'];
		} else if (array_key_exists('path',$p)) {
			$link = $p['path'];
		}
		if ($p['menu_name'][0]!='!') {
			$crumbs[] = array(
				'name' => $p['menu_name'],
				'link' => ((int)$p['hidden']) ? '' : $link
			);
		}
	}
	return $crumbs;
}


function show($template, $name, $crumbs=array(), $title='', $keywords='', $descr='')
{
	global $smarty, $lang;

	$smarty->assign('name',$name);
	$smarty->assign('crumbs',$crumbs);
	$smarty->assign('title',$title);
	$smarty->assign('keywords',$keywords);
	$smarty->assign('descr',$descr);
	
	$smarty->assign('tpl', "$template.tpl");

	$smarty->display('main.tpl');
}

?>